﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace NotificationCenterSample.Migrations;

public partial class notificationcenter : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.CreateTable(
            name: "AbpNotifications",
            columns: table => new
            {
                Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                NotificationName = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                Data = table.Column<string>(type: "nvarchar(max)", maxLength: 1048576, nullable: false),
                DataTypeName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                EntityTypeName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                EntityId = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                Severity = table.Column<byte>(type: "tinyint", nullable: false),
                CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpNotifications", x => x.Id);
            });

        migrationBuilder.CreateTable(
            name: "AbpNotificationSubscriptions",
            columns: table => new
            {
                UserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                NotificationName = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                EntityTypeName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                EntityId = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpNotificationSubscriptions", x => new { x.UserId, x.NotificationName, x.EntityTypeName, x.EntityId });
            });

        migrationBuilder.CreateTable(
            name: "AbpUserNotifications",
            columns: table => new
            {
                UserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                NotificationId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                State = table.Column<int>(type: "int", nullable: false),
                CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpUserNotifications", x => new { x.UserId, x.NotificationId });
                table.ForeignKey(
                    name: "FK_AbpUserNotifications_AbpNotifications_NotificationId",
                    column: x => x.NotificationId,
                    principalTable: "AbpNotifications",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

        migrationBuilder.CreateIndex(
            name: "IX_AbpNotifications_CreationTime_Id",
            table: "AbpNotifications",
            columns: new[] { "CreationTime", "Id" });

        migrationBuilder.CreateIndex(
            name: "IX_AbpNotificationSubscriptions_CreationTime_UserId",
            table: "AbpNotificationSubscriptions",
            columns: new[] { "CreationTime", "UserId" });

        migrationBuilder.CreateIndex(
            name: "IX_AbpUserNotifications_NotificationId",
            table: "AbpUserNotifications",
            column: "NotificationId");

        migrationBuilder.CreateIndex(
            name: "IX_AbpUserNotifications_UserId",
            table: "AbpUserNotifications",
            column: "UserId");
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropTable(
            name: "AbpNotificationSubscriptions");

        migrationBuilder.DropTable(
            name: "AbpUserNotifications");

        migrationBuilder.DropTable(
            name: "AbpNotifications");
    }
}
